﻿using IRepositories;
using iService;
using iService.BASE;
using Repositories;
using Service.BASE;
using swiftCode.Bbs.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Service
{
    public class UserService : BaseServices<User>, IUserService
    {
        //public IUserRepositories dal = new UserRepositories();

        public readonly IUserRepositories dal;
        public UserService(IUserRepositories dalRep)
        {
            dal = dalRep;
        }
        public async Task<User> addUserInfor(User user, bool autoSave = false)
        {
            return await dal.InsertAsync(user, autoSave);
        }

        public async Task<List<User>> GetAllUser()
        {
            return await dal.GetListAsync();
        }

        public async Task<User> getSelfInfor(Expression<Func<User, bool>> expression)
        {
            return await dal.GetAsync(expression);
        }

        public async Task<User> login(Expression<Func<User, bool>> expression)
        {
           return await dal.GetAsync(expression);
        }

        public async Task removeUserInfor(Expression<Func<User, bool>> expression, bool autoSave = false)
        {
            await dal.DeleteAsync(expression, autoSave);
        }

        public async Task<List<User>> selectAllUser(Expression<Func<User, bool>> expression)
        {
            return await dal.GetListAsync(expression);
        }

        public async Task<User> selectUser(Expression<Func<User, bool>> expression)
        {
            return await dal.FindAsyncNoTrack(expression);
        }

        public async Task<User> updateUserInfor(User user, bool autoSave = false)
        {
            return await dal.UpdateAsync(user, autoSave);
        }
    }
}
